easy-rpc

easy-rpc Syntax

easy-rpc uses a custom declaration language to specify the endpoints. In this section this language will be explained.

If you are looking for available configuration options to configure the .json files, see the configuration options..

Endpoints

Endpoints allways consist of at least a role and a name. This is the absolute minumum for a valid endpoint:

example.erpc
erpc
Backend ping()

Endpoints can have parameters and return types. These can be any valid easy-rpc type.

example.erpc
erpc
// Endpoint with a parameter
Backend logToServerConsole(message string)
// Endpoint with a return type
Backend getCurrentTime() int32
// Endpoint with a signle parameter and return type
Backend echo(echoMessage string) string
// Endpoint with multiple parameters and a return type
Backend sendMessageTo(message string, userId int) string

Types

There are three kinds of types in easy-rpc.

Primitive types

As in many other languages, easy-rpc knows a fixed set of primitive types.

Identifier Description
boolean A value which can be true or false
int A whole number (16bit)
int8 A whole number (8bit)
int16 A whole number (16bit)
int32 A whole number (32bit)
int64 A whole number (64bit)
float A floating point number (32bit)
float32 A floating point number (32bit)
float64 A floating point number (64bit)
string A string of characters

Enum types

An enum value is a value which is one of a fixed set. Values are separated by a |. Any valid easy-rpc type can be used.

example.erpc
erpc
Backend example(enumParameter "example" | 420 | true | string | MyCustomType) "success" | "error"

Custom types

Custom types are user defined types consisting of other user defined types or primitive types.

example.erpc
erpc
type ExampleType {
field1 string
field2 "ex" | "ample"
}
type AnotherType {
field1 ExampleType
}

Arrays

Primitive or user defined types can be arrays. Arrays are marked via a [] behind the type. Arrays can have a fixed size.

example.erpc
erpc
type Player {
name string
achievements string[]
levelsCompleted boolean[99]
}

Optionals

Fields and parameters can be optional. This indicates, that the field or parameter might not be set. To mark a field or parameter as optional, suffix it with a questionmark

example.erpc
erpc
type Player {
name string
secondName? string
}
Backend exampleEndpoint(requiredParameter string, optionalParameter? string)

Comments

easy-rpc allows for two kinds of comments: Disposeable and documentational. Disposeable comments are ignored while transpiling. Documentational comments are transferred into the generated types and methods.

example.erpc
erpc
/**
This represents a player of the game
*/
type Player {
/**
This comment will be documentational
*/
name string
/*
This one will be ignored
*/
achievements string[]
// I'm going to be ignored
levelsCompleted boolean[99]
# Me too
}
/**
This returns the player by their name
*/
Backend getPlayer(name string) Player